package com.foreknow.elm.controller;

import com.foreknow.elm.po.DeliveryAddress;
import com.foreknow.elm.service.DeliveryAddressService;
import com.foreknow.elm.service.Impl.DeliveryAddressServiceImpl;

import javax.servlet.http.HttpServletRequest;
import java.sql.SQLException;
import java.util.List;

public class DeliveryAddressController {

    public Object listDeliveryAddressByUserId(HttpServletRequest request) {
        DeliveryAddressService das=new DeliveryAddressServiceImpl();
        String userId=request.getParameter("userId");
        List<DeliveryAddress> list=das.listDeliveryAddressByUserId(userId);
        return list;
    }

    public Object getDeliveryAddressById(HttpServletRequest request) {
        DeliveryAddressService das=new DeliveryAddressServiceImpl();
        int daId=Integer.parseInt(request.getParameter("daId"));
        DeliveryAddress da=das.getDeliveryAddressById(daId);
        return da;
    }

    public Object saveDeliveryAddress(HttpServletRequest request) {
        DeliveryAddressService das=new DeliveryAddressServiceImpl();
        String contactName=request.getParameter("contactName");
        int contactSex=Integer.parseInt(request.getParameter("contactSex"));
        String contactTel=request.getParameter("contactTel");
        String address=request.getParameter("address");
        String userId=request.getParameter("userId");
        int i=das.saveDeliveryAddress(contactName,contactSex,contactTel,address,userId);
        return i;
    }

    public Object updateDeliveryAddress(HttpServletRequest request) {
        DeliveryAddressService das=new DeliveryAddressServiceImpl();
        int daId=Integer.parseInt(request.getParameter("daId"));
        String contactName=request.getParameter("contactName");
        int contactSex=Integer.parseInt(request.getParameter("contactSex"));
        String contactTel=request.getParameter("contactTel");
        String address=request.getParameter("address");
        String userId=request.getParameter("userId");
        int i=das.updateDeliveryAddress(daId,contactName,contactSex,contactTel,address,userId);
        return i;
    }

    public Object removeDeliveryAddress(HttpServletRequest request) {
        DeliveryAddressService das=new DeliveryAddressServiceImpl();
        int daId=Integer.parseInt(request.getParameter("daId"));
        int i=das.removeDeliveryAddress(daId);
        return i;
    }
}
